package day02;

import day01.Demo03;

public class Demo4 implements Runnable{
    int tickets=100;
    public void run(){
        String name=Thread.currentThread().getName();
        for (int i = 0; i < 100; i++) {
            synchronized (this){
                if(tickets>0){
                    tickets--;
                    System.out.println(name+"售票成功，剩余"+tickets);
                }
            }
        }
    }

    public static void main(String[] args) {
        Demo4 d=new Demo4();
        new Thread(d,"窗口一").start();
        new Thread(d,"窗口二").start();

    }
}
